import streamlit as st
import pandas as pd
import altair as alt
import plotly.express as px           # pip install plotly
from bokeh.plotting import figure     # pip install --force-reinstall --no-deps bokeh==2.4.3
from bokeh.models import ColumnDataSource

# 示例数据
data = {
    'Year': [2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009],
    'Sales': [10, 15, 13, 17, 18, 19, 20, 21, 22, 23],
    'Expenses': [7, 8, 9, 11, 13, 15, 17, 19, 21, 23]
}
df = pd.DataFrame(data)

# Altair图表
chart_altair = alt.Chart(df).mark_line().encode(
    x='Year',
    y='Sales',
    color='Sales'
)

# Plotly图表
chart_plotly = px.line(df, x='Year', y='Expenses', title='Expenses Over Time')

# Bokeh图表
source_bokeh = ColumnDataSource(df)
p = figure(title="Bokeh Expenses Chart", x_axis_label='Year', y_axis_label='Expenses')
p.line('Year', 'Expenses', source=source_bokeh)

# 用户选择图表类型
chart_type = st.radio("选择图表类型", ('Altair', 'Plotly', 'Bokeh'))

# 根据用户选择显示图表
if chart_type == 'Altair':
    st.altair_chart(chart_altair, use_container_width=True)
elif chart_type == 'Plotly':
    st.plotly_chart(chart_plotly, use_container_width=True)
elif chart_type == 'Bokeh':
    st.bokeh_chart(p, use_container_width=True)

# 控制流示例：基于用户选择动态显示信息
option = st.selectbox('请选择一个选项', ('展示A', '展示B', '展示C'))

if option == '展示A':
    st.write("这里是展示A的内容。")
elif option == '展示B':
    st.write("这里是展示B的内容。")
else:
    st.write("这里是展示C的内容。")